home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 10 / FreelogHS10.iso / Buzz / Buzz_Advanced_Pack.exe / {app} / Dev / Elak dist 2.cpp < prev    next >
C/C++ Source or Header  |  2001-08-27  |  4KB  |  296 lines

  1. /**
  2. * Elak Dist 2
  3. * crappy forms of distortion
  4. *
  5. * But hey, I listen to M÷torhead
  6. *
  7. **/
  8.  
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <assert.h>
  12. #include <math.h>
  13. #include "../MachineInterface.h"
  14. #include <stdio.h>
  15.  
  16.  
  17. CMachineParameter const paraScatterInterval = 
  18.     pt_byte,                                        // type
  19.     "ScatterInt",
  20.     "Interval between scatters",                        // description
  21.     0,                                                // MinValue    
  22.     254,                                            // MaxValue
  23.     0xff,                                            // NoValue
  24.     MPF_STATE,                                        // Flags
  25.     0x200,
  26. };
  27.  
  28. CMachineParameter const paraScatterAmount = 
  29.     pt_word,                                        // type
  30.     "ScatterAmount",
  31.     "The level of the scattering",                        // description
  32.     1,                                                // MinValue    
  33.     0xfffe,                                            // MaxValue
  34.     0xffff,                                            // NoValue
  35.     MPF_STATE,                                        // Flags
  36.     0x200,
  37. };
  38.  
  39. CMachineParameter const paraKindOf = 
  40.     pt_byte,                                        // type
  41.     "KindOf",
  42.     "The kind of scattering",                        // description
  43.     1,                                                // MinValue    
  44.     3,                                                // MaxValue
  45.     0xfe,                                            // NoValue
  46.     MPF_STATE,                                        // Flags
  47.     0x200,
  48. };
  49.  
  50.  
  51. CMachineParameter const *pParameters[] = 
  52.     // global
  53.     ¶ScatterInterval,
  54.     ¶ScatterAmount,
  55.     ¶KindOf
  56.     
  57. };
  58.  
  59. CMachineAttribute const attrSymmetric = 
  60. {
  61.     "Symmetric",
  62.     0,
  63.     1,
  64.     0
  65. };
  66. CMachineAttribute const *pAttributes[] = 
  67. {
  68.     &attrSymmetric
  69. };
  70.  
  71. #pragma pack(1)        
  72.  
  73. class gvals
  74. {
  75. public:
  76.     byte scatterInterval;
  77.     word scatterAmount;
  78.     byte kindOf;
  79. };
  80. class avals
  81. {
  82. public:
  83.     int symmetric;
  84. };
  85.  
  86.  
  87. #pragma pack()
  88.  
  89. CMachineInfo const MacInfo = 
  90. {
  91.     MT_EFFECT,                                // type
  92.     MI_VERSION,    
  93.     0,                                        // flags
  94.     0,                                        // min tracks
  95.     0,                                        // max tracks
  96.     3,                                        // numGlobalParameters
  97.     0,                                        // numTrackParameters
  98.     pParameters,
  99.     0,
  100.     NULL,
  101. #ifdef _DEBUG
  102.     "Elak Dist 2(Debug build)",        // name
  103. #else
  104.     "Elak Dist 2",                    // name
  105. #endif
  106.     "ElakDist2",                                    // short name
  107.     "Johan Larsby",                        // author
  108.     NULL
  109. };
  110.  
  111.  
  112. class mi : public CMachineInterface
  113. {
  114. public:
  115.     mi();
  116.     virtual ~mi();
  117.  
  118.     virtual void Init(CMachineDataInput * const pi);
  119.     virtual void Tick();
  120.     virtual bool mi::Work(float *psamples,int numsamples, int const mode);
  121.  
  122.     
  123.  
  124. private:
  125.  
  126.     byte ScatterInterval;
  127.     word ScatterAmount;
  128.     byte  KindOf;
  129.  
  130.     word count;
  131.     word mR;
  132.     word mR2;
  133.  
  134.     gvals gval;
  135. //    avals aval;
  136.  
  137. };
  138.  
  139. DLL_EXPORTS
  140.  
  141. mi::mi()
  142. {
  143.     GlobalVals = &gval;
  144.     AttrVals = NULL;
  145. }
  146.  
  147. mi::~mi()
  148. {
  149. }
  150.  
  151. void mi::Init(CMachineDataInput * const pi)
  152. {
  153.     ScatterInterval = 1;
  154.     ScatterAmount = 1;
  155.     KindOf = 1;
  156.     count = 0;
  157.  
  158.  
  159. }
  160.  
  161. void mi::Tick()
  162. {
  163.  
  164.         if (gval.scatterInterval != paraScatterInterval.NoValue)
  165.         ScatterInterval = (gval.scatterInterval);
  166.  
  167.         if (gval.scatterAmount != paraScatterAmount.NoValue)
  168.         ScatterAmount = (gval.scatterAmount);
  169.  
  170.         if (gval.kindOf!= paraKindOf.NoValue)
  171.         KindOf = (gval.kindOf);
  172. }
  173.  
  174.  
  175.  
  176. bool mi::Work(float *psamples, int numsamples, int const mode)
  177. {
  178.     if (mode == WM_WRITE) 
  179.         return false;
  180.  
  181.     if (mode == WM_NOIO) //
  182.         return false;
  183.  
  184.     if (mode == WM_READ)
  185.         return true;
  186.  
  187.  
  188.  
  189.     if (KindOf == 1)
  190.     {
  191.         do 
  192.         {
  193.             double const s = *psamples;
  194.     
  195.                 if (count > ScatterInterval)
  196.                 {
  197.                     count =0;
  198.                     mR = rand()%(ScatterAmount);
  199.                     *psamples = mR ;
  200.                 }
  201.     
  202.                 count ++;
  203.  
  204.                 if (s >= 65534)
  205.                     *psamples = 65534;
  206.                 else if (s <= -65534)
  207.                     *psamples = -65534;
  208.  
  209.                 psamples++;
  210.  
  211.             
  212.         } while(--numsamples);
  213.     }
  214.  
  215.  
  216.     else if (KindOf == 2)
  217.     {
  218.         do 
  219.         {
  220.             double const s = *psamples;
  221.     
  222.                 if (count > ScatterInterval)
  223.                 {
  224.                     count =0;
  225.                     mR = rand()%(ScatterAmount);
  226.                     mR2 = rand()%(2);
  227.                     if (mR2==2)
  228.                     {
  229.                         *psamples = (*psamples + mR)/2 ;
  230.                     }
  231.                     else
  232.                     {
  233.                         *psamples = (*psamples - mR)/2 ;
  234.                     }
  235.  
  236.  
  237.                 }
  238.     
  239.                 count ++;
  240.  
  241.                 if (s >= 65534)
  242.                     *psamples = 65534;
  243.                 else if (s <= -65534)
  244.                     *psamples = -65534;
  245.  
  246.                 psamples++;
  247.  
  248.             
  249.         } while(--numsamples);
  250.  
  251.     }
  252.  
  253.     else if (KindOf == 3)
  254.     {
  255.  
  256.                 {
  257.             double const s = *psamples;
  258.     
  259.                 if (count < ScatterInterval/2)
  260.                 {
  261.                     count =0;
  262.                     mR = rand()%(ScatterAmount);
  263.                     if (s >= 0)
  264.                     {
  265.                         *psamples =- *psamples  ;
  266.                     }
  267.                     else
  268.                     {
  269.                         *psamples =+ *psamples ;        
  270.                     }
  271.  
  272.                 }
  273.     
  274.                 count ++;
  275.  
  276.                 if (s >= 65534)
  277.                     *psamples = 65534;
  278.                 else if (s <= -65534)
  279.                     *psamples = -65534;
  280.  
  281.                 psamples++;
  282.  
  283.             
  284.         } while(--numsamples);
  285.  
  286.     }
  287.  
  288.     return true;
  289. }
  290.  
  291.  
  292.